<?php
	// Load the Qcodo Development Framework
	require('../includes/prepend.inc.php');

	/**
	 * This is a quick-and-dirty draft QForm object to do Create, Edit, and Delete functionality
	 * of the Project class.  It uses the code-generated
	 * ProjectMetaControl class, which has meta-methods to help with
	 * easily creating/defining controls to modify the fields of a Project columns.
	 *
	 * Any display customizations and presentation-tier logic can be implemented
	 * here by overriding existing or implementing new methods, properties and variables.
	 * 
	 * NOTE: This file is overwritten on any code regenerations.  If you want to make
	 * permanent changes, it is STRONGLY RECOMMENDED to move both project_edit.php AND
	 * project_edit.tpl.php out of this Form Drafts directory.
	 *
	 * @package My Application
	 * @subpackage Drafts
	 */
	class ProjectEditForm extends QForm {
		// Local instance of the ProjectMetaControl
		protected $mctProject;
		protected $ProjectFile;
		protected $lblMessage;
		protected $btnButton;

		// Controls for Project's Data Fields
		protected $lblId;
		protected $lstUser;
		protected $lstCategory;
		protected $lstSubcategory;
		protected $txtTitle;
		protected $txtCategoryId1;
		protected $txtCategoryId2;
		protected $txtCategoryId3;
		protected $txtCategoryId4;
		protected $txtCategoryId5;
		protected $txtCategory;
		protected $txtDescription;
		protected $txtOs;
		protected $txtDb;
		protected $txtBudgetMin;
		protected $txtBudgetMax;
		protected $txtFeatured;
		protected $txtHideBid;
		protected $txtHideSearch;
		protected $txtGoldOnly;
		protected $txtEnable;
		protected $txtSendmail;
		protected $txtTotalBid;
		protected $calTimeLimitDate;
		protected $calPostDate;
		protected $calCancelDate;
		protected $calCloseDate;
		protected $calEndDate;
		protected $txtStatus;
		protected $txtWonUserId;
		protected $txtAverageBid;
		protected $calWonDate;
		protected $calStartDate;
		protected $calLastBidDate;
		protected $lstProjectTypeObject;
		protected $lstBudgetTypeObject;
		protected $lstTotalProjectdayTypeObject;
		protected $chkHideSearchEngine;
		protected $chkAgreementCheck;

		// Other ListBoxes (if applicable) via Unique ReverseReferences and ManyToMany References

		// Other Controls
		protected $btnSave;
		protected $btnDelete;
		protected $btnCancel;

		// Create QForm Event Handlers as Needed

//		protected function Form_Exit() {}
//		protected function Form_Load() {}
//		protected function Form_PreRender() {}

		protected function Form_Run() {
			// Security check for ALLOW_REMOTE_ADMIN
			// To allow access REGARDLESS of ALLOW_REMOTE_ADMIN, simply remove the line below
			QApplication::CheckRemoteAdmin();
		}

		protected function Form_Create() {
		
            
            $this->ProjectFile->TemporaryUploadPath =__ProjectFileUpload__;
         
		/**
		 * This Form_Validate event handler allows you to specify any custom Form Validation rules.
		 * It will also Blink() on all invalid controls, as well as Focus() on the top-most invalid control.
		 */
		protected function Form_Validate() {
			// By default, we report that Custom Validations passed
			$blnToReturn = true;

			// Custom Validation Rules
			// TODO: Be sure to set $blnToReturn to false if any custom validation fails!

			$blnFocused = false;
			foreach ($this->GetErrorControls() as $objControl) {
				// Set Focus to the top-most invalid control
				if (!$blnFocused) {
					$objControl->Focus();
					$blnFocused = true;
				}

				// Blink on ALL invalid controls
				$objControl->Blink();
			}

			return $blnToReturn;
		}

		// Button Event Handlers

		protected function btnSave_Click($strFormId, $strControlId, $strParameter) {
			// Delegate "Save" processing to the ProjectMetaControl
			$this->mctProject->SaveProject();
			$this->RedirectToListPage();
		}

		protected function btnDelete_Click($strFormId, $strControlId, $strParameter) {
			// Delegate "Delete" processing to the ProjectMetaControl
			$this->mctProject->DeleteProject();
			$this->RedirectToListPage();
		}

		protected function btnCancel_Click($strFormId, $strControlId, $strParameter) {
			$this->RedirectToListPage();
		}

		// Other Methods

		protected function RedirectToListPage() {
			QApplication::Redirect(__SUBDIRECTORY__. '/Posting/newProject2.php');
		}
	}

	// Go ahead and run this form object to render the page and its event handlers, implicitly using
	// project_edit.tpl.php as the included HTML template file
	ProjectEditForm::Run('ProjectEditForm');
?>